# -*- coding: utf-8 -*-
# @Author   : xiongjianwen
# @Time     : 2023/1/6 11:55
# @File     : new_platform_qfsz.py
# @Project  : BwProCost_Auto_v1

from airtest.core.api import *
import uiautomation as auto
import logging

from uiautomation import Click, GetPhysicalCursorPos

from utils.handle_hanshu import HANSHU

logger = logging.getLogger("airtest")
logger.setLevel(logging.ERROR)
auto_setup(__file__, devices=["Windows:///"])


# 进入取费设置界面
def goto_qfsz():
    # touch(Template(r"../data/images/tpl1672987017665.png", record_pos=(0.022, -0.142), resolution=(3520, 1080)))
    touch(Template(r"../data/images/tpl1673250557900.png", record_pos=(0.022, -0.142), resolution=(3520, 1080)))

# 取费设置界面
class NewPlat_Qfsz:
    def __init__(self,windows_name='变电站工程.zwzj - 博微电力建设计价通软件'):
        self.auto_window = auto.WindowControl(searchDepth=1, Name=windows_name)
        self.hs = HANSHU(model_name='取费设置')
        self.left,self.top,self.right,self.bottom = self.hs.inner_windows.BoundingRectangle.left,self.hs.inner_windows.BoundingRectangle.top,self.hs.inner_windows.BoundingRectangle.right,self.hs.inner_windows.BoundingRectangle.bottom
        self.qfsz_window_rect = (self.left,self.top,self.right,self.bottom)
    '''
    1、编辑取费基数
    2、编辑费率
    3、编辑备注
    4、新建费用
    5、下移
    '''
    # 根据取费表列表，选择进入哪个界面
    def goto_qfsz_list(self,item):
        if item == '大型土石方取费表':
            touch(Template(r"../data/images/tpl1672987102960.png", record_pos=(-0.019, -0.089), resolution=(3520, 1080)))

    # 设置取费内容
    def setValueOfText_qfsz(self,text,title,value):
        self.hs.setValueOfText_byTree(text,title,value)

    # 右键-新建费用
    def right_key(self,text,keyname):
        '''
        右键功能，鼠标在费用名称那一列点击右键，并选择keyname
        :param fymc: 费用名称
        :param keyname: 右键的名称，有添加、添加子级、剪切、复制等
        :return:
        '''
        self.hs.right_key(text,keyname)


    def move_qfsz(self,direction='上移'):
        if direction == '上移':
            touch(Template(r"../data/images/tpl1673250760757.png", record_pos=(-0.003, -0.122), resolution=(3520, 1080)))
        elif direction == '下移':
            touch(Template(r"../data/images/tpl1673250772094.png", record_pos=(0.022, -0.135), resolution=(3520, 1080)))
        elif direction == '左移':
            touch(Template(r"../data/images/tpl1673250781413.png", record_pos=(0.023, -0.128), resolution=(3520, 1080)))
        elif direction == '右移':
            touch(Template(r"../data/images/tpl1673250790238.png", record_pos=(0.022, -0.122), resolution=(3520, 1080)))

if __name__ == '__main__':
    goto_qfsz()
    np = NewPlat_Qfsz()
    np.setValueOfText_qfsz('人工费','备注','测试')
    # np.setValueOfText_qfsz('人工费',3,'90')
    # np.setValueOfText_qfsz('人工费',4,'测试备注')
    np.right_key('人工费','添加')
    # np.setValueOfText_qfsz('新费用', 2, '测试移动')
    # keyevent('{ENTER}')
    x_y = GetPhysicalCursorPos() # 获取鼠标当前位置
    # print(x_y)
    Click(x_y[0],x_y[1])
    np.move_qfsz()
    np.move_qfsz('下移')

